package com.vincent.controller.basic;

import com.vincent.common.enums.SessionEnum;
import com.vincent.common.utils.ResultMapUtil;
import com.vincent.service.DecoratorService;
import com.vincent.service.MenuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * Created by Vincent on 2014/12/20.
 */
@Controller
@RequestMapping("/decorator")
public class DecoratorController {
    @Resource
    private DecoratorService decoratorService;


    /**
     * 前端顶部模板
     * @return
     */
    @RequestMapping("/shop-head")
    public String shopHeadDecorators(HttpServletRequest request){
        Map<String, Object> serviceMap = decoratorService.findShopDecorator();
        Object successObj = ResultMapUtil.getSuccessObj(serviceMap);
        request.setAttribute("data",successObj);
        return "/decorators/shop-head";
    }
    @RequestMapping("/admin-login")
    public String adminLoing(HttpServletRequest request){
        Map<String, Object> serviceMap = decoratorService.findAdminLoginDecorator();
        Object successObj = ResultMapUtil.getSuccessObj(serviceMap);
        request.setAttribute("data",successObj);
        return "/decorators/admin-login";
    }

    @RequestMapping("/admin-main")
    public String adminMain(HttpServletRequest request,HttpSession session){
        Object errorObj = session.getAttribute(SessionEnum.ERRORMSG.getCode());
        if(errorObj!=null){
            request.setAttribute(SessionEnum.ERRORMSG.getCode(),errorObj);
            session.removeAttribute(SessionEnum.ERRORMSG.getCode());
        }else{
            Object successObj = session.getAttribute(SessionEnum.SUCCESSMSG.getCode());
            if(successObj!=null){
                request.setAttribute(SessionEnum.SUCCESSMSG.getCode(),successObj);
                session.removeAttribute(SessionEnum.SUCCESSMSG.getCode());
            }
        }
        Map<String, Object> serviceMap = decoratorService.findAdminLoginSuccessDecorator();
        Object successObj = ResultMapUtil.getSuccessObj(serviceMap);
        request.setAttribute("data",successObj);
        return "/decorators/admin-main";
    }
}
